<script lang="tsx">
/**
 * 全局系统配置
 */
export default {
  name: "system-setting"
}
</script>

<script lang="tsx" setup>
import {ref} from "vue"
import {definePageModel, PageModel} from "@/framework"

/**
 * 页面模型
 */
const pageModelRef = ref()
const config = definePageModel<any>({
  url: "/api/SystemConfig",
  getImmediate: true,
  searchForm: {
    els: [
      {
        eType: 'el-input',
        prop: "keyword",
        props: {
          placeholder: "关键字",
          clearable: true
        }
      },
      {
        eType: "el-date-picker",
        prop: "startTime",
        props: {
          valueFormat: "YYYY-MM-DD",
          placeholder: "创建时间-起始",
          clearable: true
        }
      },
      {
        eType: "el-date-picker",
        prop: "endTime",
        props: {
          valueFormat: "YYYY-MM-DD",
          placeholder: "创建时间-结束",
          clearable: true
        }
      }
    ]
  },
  programForm: {
    els: [
      {
        label: "新增",
        eType: 'el-button',
        props: {
          type: "primary"
        },
        event: "add"
      },
      {
        label: "导出",
        eType: 'el-button',
        event: "export"
      }
    ]
  },
  table: {
    page: {
      enable: true,
      pageSize: 20
    },
    selection: true,
    operation: {
      width: 100,
      els: [
        {
          eType: "el-button",
          label: "编辑",
          event: "edit",
          props: {
            type: "primary",
            link: true
          }
        },
        {
          eType: "el-button",
          label: "删除",
          event: "delete",
          props: {
            type: "primary",
            link: true
          }
        }
      ]
    },
    props: {
      stripe: false,
      border: false
    },
    els: [
      {
        label: "配置名称",
        prop: "code",
        minWidth: 120
      },
      {
        label: "配置内容",
        prop: "content",
        minWidth: 120
      },
      {
        label: "创建时间",
        prop: "createTime",
        minWidth: 200,
        renderFn(data) {
          return <span>{data.createTime?.split(' ')[0]}</span>
        }
      }
    ]
  },
  form: {
    title: "新增/编辑",
    width: 500,
    sheetForm: {
      labelWidth: "100px",
      required: ['code', 'content'],
      els: [
        {
          label: "配置名称",
          eType: "el-input",
          prop: "code",
          props: {
            placeholder: "配置名称",
            clearable: true
          }
        },
        {
          label: "配置内容",
          eType: "el-input",
          prop: "content",
          props: {
            placeholder: "配置内容",
            clearable: true
          }
        }
      ]
    }
  }
})

/**
 * 新增
 */
const handleAdd = () => {
  pageModelRef.value.handleAdd()
}

/**
 * 编辑
 */
const handleEdit = (row: any) => {
  pageModelRef.value.handleEdit(row)
}

/**
 * 删除
 */
const handleDelete = (row: any) => {
  pageModelRef.value.handleDelete(row)
}

/**
 * 导出
 */
const handleExport = () => {
  const selections = pageModelRef.value.getTableSelectData()
  pageModelRef.value.handleExport(selections)
}
</script>

<template>
  <PageModel ref="pageModelRef" :PageModel="config" @add="handleAdd" @delete="handleDelete" @edit="handleEdit"
             @export="handleExport"/>
</template>

<style lang="scss" scoped>
</style>
